<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('文件资源库列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>仓库名称：</label>
                                <input type="text" name="repositoryName"/>
                            </li>
                            <li>
                                <label>仓库路径：</label>
                                <input type="text" name="repositoryLocation"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="busi:repository:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('watchdog:repository:edit')}]];
        var removeFlag = [[${@permission.hasPermi('watchdog:repository:remove')}]];
        var updateFlag = [[${@permission.hasPermi('watchdog:repository_log:updateRepository')}]];
        var forceUpdateFlag = [[${@permission.hasPermi('watchdog:repository_log:forceUpdateRepository')}]];
        var exportFlag = [[${@permission.hasPermi('watchdog:repository_log:exportFlag')}]];
        var prefix = ctx + "watchdog/repository";
        var datas = [[${@dict.getType('sys_normal_disable')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "文件资源库",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'repositoryId',
                    title: '仓库ID',
                    visible: false
                },
                {
                    field: 'repositoryName',
                    title: '仓库名称',
                    formatter: function(value, row, index) {
                        if (row.status === '0') {
                            return '<a href="javascript:void(0)" onclick="$.repositoryDetail(\'' + row.repositoryId + '\')">' + value + '</a>';
                        } else {
                            return value;
                        }

                    }
                },
                {
                    field: 'repositoryLocation',
                    title: '仓库路径'
                },
                {
                    field: 'repositoryDescription',
                    title: '仓库描述'
                },
                {
                    field: 'repositoryType',
                    title: '仓库类型'
                },
                {
                    field: 'gitAuthType',
                    title: '权限认证方式'
                },
                {
                    field: 'gitUri',
                    title: 'git地址'
                },
                {
                    field: 'gitBranch',
                    title: 'git分支'
                },
                {
                    field: 'gitSshKey',
                    title: 'SSH KEY'
                },
                {
                    field: 'gitUsername',
                    title: 'git用户名'
                },
                {
                    field: 'gitPassword',
                    title: 'git密码'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'createdTime',
                    title: '创建时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    witch: 700,
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.repositoryId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.repositoryId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + updateFlag + '" href="javascript:void(0)" onclick="$.updateRep(\'' + row.repositoryId + '\')"><i class="fa fa-edit"></i>更新仓库</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + forceUpdateFlag + '" href="javascript:void(0)" onclick="$.forceUpdateRep(\'' + row.repositoryId + '\')"><i class="fa fa-remove">强制更新</i></a>');
                        actions.push('<a class="btn btn-warning btn-xs ' + exportFlag + '" href="'+prefix+'/exportRepo/'+row.repositoryId+'"><i class="fa fa-remove"></i>导出仓库</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

            // 跟新GIT仓库
            $.updateRep = function(repositoryId) {
                $.modal.confirm("确定更新仓库”"+repositoryId+"“" + "吗？", function() {
                    var url = "/watchdog/repository/updateRepository/"+repositoryId;
                    $.operate.submit(url, 'get', "json");
                });
            };
            $.forceUpdateRep = function (repositoryId) {
                $.modal.confirm("确定强制更新仓库”"+repositoryId+"“" + "吗？", function() {
                    var url = "/watchdog/repository/forceUpdateRepository/"+repositoryId;
                    $.operate.submit(url, 'get', "json");
                });
            };

            $.repositoryDetail = function (repositoryId) {
                var url = prefix + '/detail/' + repositoryId;
                // console.log("url="+ url)
                $.modal.openTab("参数组数据", url);
            }
        });
    </script>
</body>
</html>